#页面类：登录页面类

from selenium.webdriver.common.by import By

from utils.page_base import PageBase

class PageLogin(PageBase):
    pathUrl="/simple/login"
    loc_zanhao=By.NAME,"login_info" #账号框
    loc_pwd=By.NAME,"password" #密码框
    loc_loginButton=By.CSS_SELECTOR,"input.input_submit[value='登录']" #登录按钮
    loc_erroTipDiv=By.CSS_SELECTOR,"div.prompt" #错误提示div

    def __init__(self,driver,base_url):
        PageBase.__init__(self,driver,base_url)

    #打开登录页
    def openUrl(self):
        self.open(PageLogin.pathUrl)

    #输入某账号
    def input_zanhao(self,zanhao):
        self.input(loc=PageLogin.loc_zanhao,data=zanhao)

    #输入某密码
    def input_pwd(self,pwd):
        self.input(loc=PageLogin.loc_pwd, data=pwd)


    #点击“登录按钮”
    def click_login(self):
        self.click(loc=PageLogin.loc_loginButton)

    #获取错误提示div标签的文本内容
    def getErrorTipDivText(self):
        return self.getEleAttrOrText(loc=PageLogin.loc_erroTipDiv,isStrip=True)

    #判断错误提示div标签是否存在
    def isExistsErrorTipDiv(self):
        return self.isExists(loc=PageLogin.loc_erroTipDiv)

    #获取密码框的class属性的值：“input_text    invalid-text”
    def getPwdAttrClass(self):
        return self.getEleAttrOrText(loc=PageLogin.loc_pwd,type="attr",attrName="class",isStrip=True)

    #获取账号框的class属性的值
    def getZanhaoAttrClass(self):
        return self.getEleAttrOrText(loc=PageLogin.loc_zanhao, type="attr", attrName="class", isStrip=True)

